package leetcode.view1709;

import java.util.stream.Stream;

public class Solution {

	public int getKthMagicNumber(int k) {
		int[] primes = new int[] { 3, 5, 7 };
		int[] idxs = new int[primes.length];
		int[] dp = new int[k];
		dp[0] = 1;
		for (int i = 1; i < k; i++) {
			long min = dp[idxs[0]] * primes[0];
			for (int j = 1; j < primes.length; j++) {
				min = Math.min(min, dp[idxs[j]] * primes[j]);
			}
			for (int j = 0; j < primes.length; j++) {
				if (dp[idxs[j]] * primes[j] == min) {
					idxs[j]++;
					dp[i] = (int) min;
				}
			}
		}
		return dp[k - 1];
	}

}
